// 查看单据历程
<template>
  <div class="document-history-box">
    <DicTable
        height="100%"
        stripe
        highlight-current-row
        highlight-hover-row
        max-height="600"
        ref="GBLtable"
        border
        header-row-class-name="header-row-class"
        row-class-name="ne-row-class"
        :columnData="GBLtbs.tableColumns"
        :tableData="GBLtbs.tableData"
        :loading="GBLtbs.tableLoading"
        :currentPage="~~GBLtbs.tablePage.pageIndex"
        :pageSize="~~GBLtbs.tablePage.pageSize"
        :totalResult="~~GBLtbs.tablePage.rowCount"
        :pager="true"
        @on-page-change="handlePageChange"
    >
      <template #orderNbr="{ row }">
        <a @click="goDetailView(row)"
            style="color: blue; cursor: pointer">{{JSON.parse(row.batchNbr) > 0
            ? row.orderNbr +
            "-" +
            row.batchNbr +
            "(" +
            row.orderItemSeq +
            ")"
            : row.orderNbr + "(" + row.orderItemSeq + ")"}}</a>
      </template>
      <template #reqDate="{ row }">
        <p>{{row.reqDate?dateFormat(row.reqDate):''}}</p>
      </template>
      <template #orderDate="{ row }">
        <p>{{row.orderDate?dateFormat(row.orderDate):''}}</p>
      </template>
      <template #handleDate="{ row }">
        <p>{{row.handleDate?dateFormat(row.handleDate):''}}</p>
      </template>
      <template #finishTime="{ row }">
        <p>{{row.finishTime?dateFormat(row.finishTime):''}}</p>
      </template>
      <template  #liucheng="{ row }">
        <a @click="toFlowChart(row)">
          <i class="el-icon-share orange" style="font-size: 0.18rem"></i>
        </a>
        <!-- </router-link> -->
      </template>
    </DicTable>
  </div>
</template>
<script>
import CustOrderService from "@/api/order/CustOrderService";
import commonUtil from "@/utils/common";
import DicTable from "@/components/public/DicTable";
export default {
  name: 'DocumentHistory',
  data() {
    return {
      GBLtbs: {
        tableColumns: [
          { type: "seq", title: "序号", width: "5%" },
          { slotName: "orderNbr", title: "流水号",width: '10%'},
          { field: "modOldOrderNbr", title: "原单流水号",width: '10%'},
          { slotName: "liucheng", title: "流程" },
          { field: "prodOfferName", title: "销售品名称" },
          { field: "productName", title: "产品名称" },
          { field: "applyInfo", title: "登记事项" },
          { field: "orderItemStatusCd", title: "单据状态" },
          { field: "handleOrderType", title: "单据类型" },
          { slotName: "handleDate", title: "受理日期",width: '10%'},
          { slotName: "reqDate", title: "需求单要求完成日期",width: '9%'},
          { slotName: "orderDate", title: "订单要求完成日期",width: '9%'},
          { slotName: "finishTime", title: "完成时间",width: '9%'}
        ],
        tableData: [],
        tableLoading: false,
        tablePage: {
          pageIndex: 1,
          pageSize: 10,
          rowCount: 0,
        },
      },
    };
  },
  props: {
    changeRow:{
      type: Object
    }
  },
  mounted() {

  },
  created() {
    this.getList();
  },
  components: {DicTable},
  methods: {
    goDetailView: function (row) {
      console.log(row);
      //跳转产品详情
      sessionStorage.setItem("changeRow", JSON.stringify(row));
      // if(row.lastStateCd   50030002)
      const ppmCondition = {
        productId: row.prodId ? row.prodId : 80008007,
        serviceOfferId: "4010100000",
        modType: "50200003",
        optionId: "310", //需求单审核前后/订单审核前后/产品实例库  310，311，312，313，314
      };
      if (
          this.custorder.audState == "审核同意" &&
          row.lastStateCd == "50030002"
      ) {
        ppmCondition.optionId = "311";
      } else if (
          this.custorder.audState == "审核同意" &&
          row.lastStateCd == "50030003"
      ) {
        ppmCondition.optionId = "313";
      } else if (
          this.custorder.audState == "待送审核" &&
          row.lastStateCd == "50030003"
      ) {
        ppmCondition.optionId = "312";
      } else if (
          this.custorder.audState == "待审核" &&
          row.lastStateCd == "50030003"
      ) {
        ppmCondition.optionId = "313";
      } else if (
          this.custorder.audState == "待审核" &&
          row.lastStateCd == "50030002"
      ) {
        ppmCondition.optionId = "311";
      }
      sessionStorage.setItem("ppmCondition", JSON.stringify(ppmCondition));
      ppmCondition.audState = this.custorder.audState;
      sessionStorage.setItem("detailCondition", JSON.stringify(ppmCondition)); //解决详情刷新缓存请求条件被覆盖问题
      window.open("orders.html?router=productinfo", "_blank");
    },
    dateFormat(date){
      return this.$util.dateFormat(date, "yyyy-MM-dd")
    },
    async getList(){
      this.GBLtbs.tableLoading = true;
      let {offerInstId,prodInstId} = this.changeRow;
      let params = {offerInstId,prodInstId};
      let newParams = {};
      for(var key in params){
        newParams[commonUtil.toCapital(key)] = params[key];
      }
      const result = await CustOrderService.qryProdOfferInstOrderProcess({...newParams,pageInfo:{pageIndex:this.GBLtbs.tablePage.pageIndex,pageSize:this.GBLtbs.tablePage.pageSize}});
      this.GBLtbs.tableLoading = false;
      if(result.code == 200){
        let data = result.meta.requestObject;
        this.GBLtbs.tableData = [];
        if(data.length>0){
          data.forEach((item,index)=>{
            this.GBLtbs.tableData.push({});
            for(var key in item){
              this.GBLtbs.tableData[index][commonUtil.toHump(key)]=item[key];
            }
          });
          this.GBLtbs.tablePage.pageSize = result.meta.pageInfo.pageSize;
          this.GBLtbs.tablePage.pageIndex = result.meta.pageInfo.pageIndex;
          this.GBLtbs.tablePage.rowCount = result.meta.pageInfo.rowCount;
        }
      }else{
        this.$message({
          showClose: true,
          message: result.meta.resultMsg,
          type: 'error'
        });
      }
      console.log(result);
    },
    // 流程图跳转
    async toFlowChart(row) {
      const result = await CustOrderService.getFlowInst({
        orderItemId: row.orderItemId,
      });
      let flowInfo = {
        processInstanceId: result.meta.FLOW_INST_ID,
        custSoNumber: row.orderNbr,
        serviceOfferName: row.applyInfo,
        prodName: row.productName,
        orderItemSeq:
            row.orderItemSeq != undefined && row.orderItemSeq != ""
                ? row.orderItemSeq
                : "",
      };
      console.log("80808080808080808080808080");
      console.log(flowInfo);
      sessionStorage.setItem("flowInfo", JSON.stringify(flowInfo));
      // this.$router.push({
      //   name: "flowChart",
      //   params: { id: result.meta.FLOW_INST_ID },
      // });
      window.open(`orders.html?router=flowChart`, "_blank");
    },
    handlePageChange({ currentPage, pageSize }) {
      this.GBLtbs.tablePage.pageIndex = currentPage;
      this.GBLtbs.tablePage.pageSize = pageSize;
      this.getList();
    },
  },
};
</script>

<style lang="scss" scoped>

</style>
